package ch.sv7.tool.dbmanager.db.fixbuilder;

import ch.sv7.tool.dbmanager.Context;
import ch.sv7.tool.dbmanager.db.ColumnSchema;
import ch.sv7.tool.dbmanager.db.dialect.Dialect;
import ch.sv7.tool.dbmanager.db.difference.MissingColumnDifference;
import ch.sv7.tool.dbmanager.db.difference.SchemaDifference;
import ch.sv7.tool.dbmanager.db.fix.CreateColumnFix;
import ch.sv7.tool.dbmanager.db.fix.SchemaFix;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class MissingColumnFixBuilder implements FixBuilder {

	public SchemaFix[] createFixes(SchemaDifference difference, Dialect dialect, Context context) {
		MissingColumnDifference missingColumnDifference = (MissingColumnDifference)difference;
		/*
		 * Clone to prevent side-effect changes to DatabaseSchema
		 */
		ColumnSchema columnToAdd = missingColumnDifference.getExpectedColumnSchema().cloneColumn();
		columnToAdd.getType().setNullable(true);
		
		SchemaFix fix = new CreateColumnFix(columnToAdd);
		return new SchemaFix[]{ fix };
	}

}
